package com.wl;

/**
 * @author wangLin
 * @version 1.0
 * @projectName singletonPattern20210423
 * @className Client
 * @date 2021-04-23 周五
 * @time 9:05
 * @description TODO
 */

/**
 * 客户端模拟
 */
public class Client {
    public static void main(String[] args) {
        LoadBalancer loadBalancer1, loadBalancer2, loadBalancer3;
        loadBalancer1 = LoadBalancer.getLoadBalancer();
        loadBalancer2 = LoadBalancer.getLoadBalancer();
        loadBalancer3 = LoadBalancer.getLoadBalancer();

        //判断服务器负载均衡是否相同
        System.out.println(loadBalancer1.hashCode());
        System.out.println(loadBalancer2.hashCode());
        System.out.println(loadBalancer3.hashCode());

//        增加服务器
        loadBalancer1.addService("service1");
        loadBalancer1.addService("service2");
        loadBalancer1.addService("service3");

        //模拟客服端请求的分发，如果输出结果为同一个server，可以将i适当放大
        for (int i = 0; i < 20; i++) {
            String service = loadBalancer1.getService();
            System.out.println("分发请求至服务器：" + service);
        }


    }

}
